//
//  RGRecordsCell.m
//  RedGrass
//
//  Created by wuyine on 2019/2/15.
//  Copyright © 2019年 hongcaosp. All rights reserved.
//

#import "RGRecordsCell.h"

@implementation RGRecordsCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.contentView.backgroundColor = UICOLOR_WITH_RGBINT(0x000000);
        [self.contentView addSubview:self.title];
        [self.contentView addSubview:self.content];
        [self.contentView addSubview:self.detail];
        
        [_title mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(16);
            make.leading.mas_equalTo(15);
        }];
        
        [_content mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(self.title.mas_leading);
            make.bottom.mas_equalTo(-16);
        }];
        
        [_detail mas_makeConstraints:^(MASConstraintMaker *make) {
            make.trailing.mas_equalTo(-15);
            make.centerY.mas_equalTo(0);
        }];
        
    }
    return self;
}

- (void)setModel:(RGRecordModel *)model {
    _model = model;
    if ([model.exIn isEqualToString:@"in"]) {
        if (model.type == 3) {
            _title.text = @"红包";
        }else if ( model.type == 4) {
            _title.text = @"邀请奖励";
        }else {
            _title.text = @"充值";
        }
        _detail.text = [NSString stringWithFormat:@"+%@",model.amount];
    }else if ([model.exIn isEqualToString:@"ex"]) {
        if (model.type == 2) {
            _title.text = @"提现";
        }else {
            _title.text = @"消费";
        }
         _detail.text = [NSString stringWithFormat:@"-%@",model.amount];
    }
    _content.text = [self makeCustomDateStringWithTime:model.createTime];
}

-(NSString *)makeCustomDateStringWithTime:(NSString *)time{
    NSString *resutStr = time;
    if([time length] == 13){
        NSTimeInterval time1 = [time integerValue] / 1000;
        NSDate *date = [NSDate dateWithTimeIntervalSince1970:time1];
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];//创建一个日期格式化器
        dateFormatter.dateFormat= @"YYYY.MM.dd";
        resutStr = [dateFormatter stringFromDate:date];
    }else if ([time length] == 10){
        NSTimeInterval time1 = [time integerValue];
        NSDate *date = [NSDate dateWithTimeIntervalSince1970:time1];
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];//创建一个日期格式化器
        dateFormatter.dateFormat= @"YYYY.MM.dd";
        resutStr = [dateFormatter stringFromDate:date];
    }
    return resutStr;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (UILabel *)title {
    if (!_title) {
        _title = [[UILabel alloc] init];
        _title.font = FONT(customFontName, 16);
        _title.textColor = UICOLOR_WITH_RGBINT(0xfffefe);
    }
    return _title;
}

- (UILabel *)content {
    if (!_content) {
        _content = [[UILabel alloc] init];
        _content.font = FONT(customFontName, 13);
        _content.textColor = UICOLOR_WITH_RGBINT(0xffffff);
    }
    return _content;
}

- (UILabel *)detail {
    if (!_detail) {
        _detail = [[UILabel alloc] init];
        _detail.font = FONT(customFontName, 18);
        _detail.textColor = UICOLOR_WITH_RGBINT(0xf73152);
    }
    return _detail;
}

@end
